home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7520 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  52 lines

  1. Path: vnetnews.value.net!usenet
  2. From: Adonis Ioannou <adonis@value.net>
  3. Newsgroups: comp.lang.c
  4. Subject: Large Number Arithmetic
  5. Date: 27 Feb 1996 05:49:40 GMT
  6. Organization: Value Net Internetwork Services Inc.
  7. Message-ID: <4gu61k$52@vnetnews.value.net>
  8. NNTP-Posting-Host: k103.value.net
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.2 (Windows; U; 16bit)
  13.  
  14. Your help will be greatly appreciated...
  15.  
  16. I am trying to create a simple calculator, which supports + - / * %, using the 
  17. following input from the command line:-
  18.  
  19.                  nnn + nnn where  nnn is an integer up to 40 digits long.
  20.  
  21. The output should also be of the same format(no scientific notations)
  22.  
  23. I have tried to read the values using 
  24.  
  25.                   scanf("%Lf", &x) where x is a long double(so that I can store these 
  26.                                                             large numbers),
  27. but after I enter more than 20 digits, I start to lose some accuracy.
  28.  
  29. I also tried to read the input into character arrays, and then convert the string 
  30. using _atold(), but had the same problem. Can anyone give me any clues or suggestions?
  31.  
  32. I am using VisualC++ 1.52, under WIN95.
  33.  
  34. Here is an example of what I mean:-
  35.  
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38.  
  39. void main(void)
  40. {      
  41.     long double x;     
  42.                  
  43.     scanf("%Lf", &x);
  44.     printf("%Lf", x);
  45. }
  46.  
  47. If I enter 12345678901234567890 I get the same result.
  48. If I enter 123456789012345678901 I get 123456789012345678904
  49.  
  50. Thanks
  51.  
  52.